package com.example.demo.dao;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.Optional;
import java.util.Set;

@Repository
public interface ScheduleRepository extends JpaRepository<Schedule, Long> {
    Set<Schedule> findByUserId(Long userId);
    void deleteByUserIdAndDate(Long userId, String date);
    void deleteByUserIdAndDateAndDateId(Long userId, String date, int dateId);
    Optional<Schedule> findByUserIdAndDateAndDateId(Long userId, String date, int dateId);
    @Query("SELECT COALESCE(MAX(s.dateId), 0) FROM Schedule s JOIN s.user u WHERE DATE(s.date) = DATE(:date) AND u.id = :userId")
    int findMaxDateIdByDateAndUserId(@Param("date") String date, @Param("userId") Long userId);

    Set<Schedule> findByUserIdAndDate(Long userId, String date);
}
